package com.example.moban.ui.activity;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.annotation.NonNull;
import android.support.v7.widget.AppCompatTextView;
import android.text.TextUtils;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alipay.sdk.app.PayResultActivity;
import com.bumptech.glide.Glide;
import com.example.moban.R;
import com.example.moban.api.HuRequest;
import com.example.moban.application.MyApplication;
import com.example.moban.base.BaseActivity;
import com.example.moban.base.BaseEvent;
import com.example.moban.beans.UserInfoBean;
import com.example.moban.beans.VersionInfoBean;
import com.example.moban.module.VersionUpdateModule;
import com.example.moban.ui.fragment.PersonCenterFragment;
import com.example.moban.utils.FeiLogUtil;
import com.example.moban.view.MainCustomBottomView;

import com.example.moban.view.badgeview.BadgeView;
import com.rzhd.coursepatriarch.common.api.base.BaseObserver;
import com.rzhd.coursepatriarch.common.constants.HttpConstants;
import com.rzhd.coursepatriarch.common.utils.APKVersionCodeUtils;
import com.rzhd.coursepatriarch.common.utils.FragmentCustomManager;
import com.rzhd.coursepatriarch.common.utils.ToastUtils;
import com.rzhd.coursepatriarch.common.utils.permission.AndPermissionUtils;
import com.rzhd.coursepatriarch.common.view.CustomEditText;


import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import java.util.Calendar;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import butterknife.BindView;
import okhttp3.RequestBody;

public class MainActivity extends BaseActivity implements VersionUpdateModule.OnInterceptListener,
        AndPermissionUtils.AddPermissionCallback {

    @BindView( R.id.frameLayoutMain )
    FrameLayout frameLayout;
    @BindView( R.id.mainCustomBottomView )
    MainCustomBottomView bottomView;
    @BindView( R.id.bootom_menu_layout )
    LinearLayout bottomMenuLayout;

    @BindView( R.id.main_activity_person_center_point_framen_layout )
    FrameLayout messagePointFrameLayout;
    @BindView( R.id.main_activity_person_center_point_text )
    AppCompatTextView messagePointText;
    @BindView( R.id.main_activity_person_center_point_badge_view )
    BadgeView badgeView;
    @BindView( R.id.main_activity_person_center_point_num_layout )
    RelativeLayout pointNumLayout;

    @BindView(R.id.menu_live_course_layout )
    LinearLayout menu_live_course_layout;

//    @BindView(R.id.activity_course_detail_comment_bottom_input_edit )
//    CustomEditText commentEdit;



    private FragmentCustomManager mFragmentCustomManager;

    private String currentShowFragmentClassName;

    private HuRequest huRequest;
//    private AdvertDialog advertDialog;
    private long lastTime;

    private int tabPosition;
    private boolean isHandPosition;

    private VersionUpdateModule versionUpdateModule;
    private AndPermissionUtils mPermissionUtils;
    /**
     * 是否执行授权方法
     */
    private boolean isExecGrant;
    private boolean isIntercept = true;
    private PersonCenterFragment schoolFragment;
    private PersonCenterFragment schoolGroupFragment;
    private PersonCenterFragment myCenterFragment;
    private PersonCenterFragment liveCourseFragment1;
    private UserInfoBean.DataBean userInfo;



//    private EmojiWidget emojiWidget;//表情
    private final static int ON_EMOJI_CHANGE = 0xc1;

    @Override
    public void setContentView(Bundle savedInstanceState) {
        mFragmentCustomManager = new FragmentCustomManager(getSupportFragmentManager());
        if (savedInstanceState != null) {
            mFragmentCustomManager.setCurrentFragment(getSupportFragmentManager().getFragment(
                    savedInstanceState, "fragment"));
        }
        setContentView( R.layout.activity_main_layout );
        ((MyApplication)getApplication()).addActivity(this);
    }

    @Override
    protected void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        if (mFragmentCustomManager != null && mFragmentCustomManager.getCurrentFragment() != null) {
            getSupportFragmentManager().putFragment(outState, "fragment", mFragmentCustomManager.getCurrentFragment());
        }
    }


    @Override
    public void initView() {
        requestFulScreen( false , true , true );
        huRequest = new HuRequest();
        EventBus.getDefault().register( this );
        tabPosition = getBundleValueInt( "tabPosition" , tabPosition );
        mCustomToolbar.setVisibility( View.GONE );


//        this.emojiWidget = new EmojiWidget(this, this, ON_EMOJI_CHANGE,
//                this.mUIHandler, this.commentEdit);

        bottomView.setMainOnClickListener(this);


        if( tabPosition != 0 ){
            onClickChange( tabPosition );
        }else{
            LinearLayout classGroupLayout = bottomView.getmLayoutClassGroup();
            onClick( classGroupLayout );
        }
        if( preferenceUtils.getLogin() ){
            String userId = preferenceUtils.getUserId();
            huanXixIMLogin( "youtangke_"+userId , "youtangke123456");
        }
        versionUpdateModule = new VersionUpdateModule( this , this );
        mPermissionUtils = new AndPermissionUtils( this , this );
        versionUpdateModule.setShowProgress( false );
        versionUpdateModule.setInterceptListener( this );



//        userInfo.setJoinClassCricle(0);
//        preferenceUtils.setUserInfo(userInfo);

        ceShiJson();


    }




    @Override
    protected void onStart() {
        super.onStart();
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            //班级圈
            case R.id.class_group_layout:
                onClickChange(0);
                break;
            //家长课堂
            case R.id.menu_patriarch_course_layout:
                onClickChange(1);
                break;
            //直播课程
            case R.id.menu_live_course_layout:
                onClickChange(2);
                break;
            //个人中心
            case R.id.menu_person_center_layout:
                onClickChange(3);
                break;
            default:
                break;
        }
    }

    public void onClickChange(int position) {
        isHandPosition = false;
        switch (position) {
            //班级圈
            case 0:
                tabPosition = 0;
                bottomView.clickChangeView(position);
                loadClassGroupFragmentPage();
                break;
            //家长课堂
            case 1:
                //=====================2019-10-11修改======================
//                if( !preferenceUtils.getLogin() ){
//                    showActivity( SecondLoginActivity.class );
//                    return;
//                }
//                showActivity( PatriarchCourseWebActivity.class );
////                tabPosition = 1;
////                bottomView.clickChangeView(position);
////                loadPatriarchCourseFragmentPage();
                //=====================2019-10-11修改======================
                break;
            //直播课程
            case 2:
                tabPosition = 2;
                bottomView.clickChangeView(position);
                loadLiveCourseFragmentPage();
                break;
            //个人中心
            case 3:
                tabPosition = 3;
                bottomView.clickChangeView(position);
                loadPersonCenterFragmentPage();
//                GetMeInfo.getMeInfo(this);//刷新个人信息
                break;
            default:
                break;
        }
    }

    /**
     * 班级圈Framgment
     */
    private void loadClassGroupFragmentPage(){



        int joinClassCricle =1;
        try {
            UserInfoBean.DataBean userInfo = preferenceUtils.getUserInfo();
            joinClassCricle = userInfo.getJoinClassCricle();
        }catch (Exception e){
            FeiLogUtil.i("fei","joinClassCricle为空");
        }
//        if (joinClassCricle==1) {
            schoolFragment = (PersonCenterFragment) mFragmentCustomManager.showFragment(R.id.frameLayoutMain, PersonCenterFragment.class);
            currentShowFragmentClassName = PersonCenterFragment.class.getSimpleName();
//        }else if (joinClassCricle==2){
//            schoolGroupFragment = (SchoolGroupFragment) mFragmentCustomManager.showFragment(R.id.frameLayoutMain, SchoolGroupFragment.class);
//            EventBus.getDefault().post( new BaseEvent<String>( BaseEvent.EventCodeContains.REFRESH_MAIN_CLASS_CIRCLE ,
//                    BaseEvent.EventNameContains.REFRESH_MAIN_CLASS_CIRCLE , "" , null ));
//            currentShowFragmentClassName = SchoolGroupFragment.class.getSimpleName();
//            mCustomToolbar.setToolbarDefault(resources.getString(R.string.class_group), true);
//        }else if (joinClassCricle==3){
//
//        }

        mCustomToolbar.setToolbarDefault(resources.getString(R.string.class_group), true);
    }

    /**
     * 家长课堂Fragment
     */
    private void loadPatriarchCourseFragmentPage(){
//        patriarchCourseFragment =
//                (PatriarchCourseFragment) mFragmentCustomManager.showFragment(R.id.frameLayoutMain,
//                        PatriarchCourseFragment.class);
//        currentShowFragmentClassName = PatriarchCourseFragment.class.getSimpleName();
//        mCustomToolbar.setToolbarDefault( resources.getString( R.string.patriarch_course ) , true );
    }

    /**
     * 直播课程Fragment
     */
    private void loadLiveCourseFragmentPage(){
//        liveCourseFragment =
//                (LiveCourseFragment) mFragmentCustomManager.showFragment(R.id.frameLayoutMain,
//                        LiveCourseFragment.class);
//        currentShowFragmentClassName = LiveCourseFragment.class.getSimpleName();
//        mCustomToolbar.setToolbarDefault( resources.getString( R.string.live_course ) , true );


        liveCourseFragment1 = (PersonCenterFragment) mFragmentCustomManager.showFragment(R.id.frameLayoutMain,
                PersonCenterFragment.class);
        currentShowFragmentClassName = PersonCenterFragment.class.getSimpleName();
        mCustomToolbar.setToolbarDefault( resources.getString( R.string.app_name ) , true );
        EventBus.getDefault().post( new BaseEvent<String>( BaseEvent.EventCodeContains.REFRESH_ARTICLE_VIDEO ,
                BaseEvent.EventNameContains.REFRESH_ARTICLE_VIDEO , "" , null ));

    }

    /**
     * 个人中心Fragment
     */
    private void loadPersonCenterFragmentPage(){
//        personCenterFragment = (PersonCenterFragment) mFragmentCustomManager.showFragment(R.id.frameLayoutMain,
//                        PersonCenterFragment.class);
//        currentShowFragmentClassName = PersonCenterFragment.class.getSimpleName();
//        //刷新数据
//        EventBus.getDefault().post( new BaseEvent<String>( BaseEvent.EventCodeContains.REFRESH_USER_INFO ,
//                BaseEvent.EventNameContains.REFRESH_USER_INFO , "" , null ));
//        mCustomToolbar.setToolbarDefault( resources.getString( R.string.person_center ) , true );

        myCenterFragment = (PersonCenterFragment) mFragmentCustomManager.showFragment(R.id.frameLayoutMain,
                PersonCenterFragment.class);
        currentShowFragmentClassName = PersonCenterFragment.class.getSimpleName();
        //刷新数据
        EventBus.getDefault().post( new BaseEvent<String>( BaseEvent.EventCodeContains.REFRESH_USER_INFO ,
                BaseEvent.EventNameContains.REFRESH_USER_INFO , "" , null ));
        mCustomToolbar.setToolbarDefault( resources.getString( R.string.person_center ) , true );

    }

    @Override
    protected void onResume() {
        super.onResume();
        if( isHandPosition ){
            onClickChange( tabPosition );
        }
        mPermissionUtils.requestPermission(AndPermissionUtils.splashPermissions);
//        GetMeInfo.getMeInfo(this);


    }

    /**
     * 获取开屏广告
     */
    private void getOpenAppAdver(){
//        Map<String , Object> params = new HashMap<>();
//        //当前页
//        params.put( "current" , 1 );
//        //页大小
//        params.put( "size" , 1 );
//        //1-家长端 2-教师端
//        params.put( "type" , 1 );
//        huRequest.getOpenAdApiList(params, new BaseObserver<String>() {
//            @Override
//            public void onNext(String json) {
//                if( TextUtils.isEmpty( json )){
//                    return;
//                }
//                AdvertisingBean bean = JSON.parseObject( json , AdvertisingBean.class );
//                if( bean == null ){
//                    return;
//                }
//                if( bean.getCode() == HttpConstants.RESPONSE_CODE_200 ){
//                    AdvertisingBean.SubDataBean data = bean.getData();
//                    if( data == null ){
//                        return;
//                    }
//                    List<AdvertisingBean.DataBean> list = data.getList();
//                    if( list == null || list.size() <= 0 ){
//                        return;
//                    }
//                    AdvertisingBean.DataBean dataBean = list.get(0);
//                    if( dataBean == null ){
//                        return;
//                    }
//                    showAdvertDialog( dataBean );
//                }else{
//                    ToastUtils.longToast( bean.getMessage() );
//                }
//            }
//        });
    }

    /**
     * 是否显示广告
     * @return
     */
    private boolean isShowAdvert(){
        String openAppDateTime = preferenceUtils.getOpenAppDateTime();
        long currentTimeMillis = System.currentTimeMillis();
        if( TextUtils.isEmpty( openAppDateTime )){
            preferenceUtils.saveOpenAppDateTime( ""+System.currentTimeMillis());
            return true;
        }
        Calendar instance = Calendar.getInstance();
        instance.setTimeInMillis( Long.parseLong( openAppDateTime ));
        int preOpenYear = instance.get( Calendar.YEAR );
        int preOpenMonth = instance.get( Calendar.MONTH );
        int preOpenDay = instance.get( Calendar.DAY_OF_MONTH );

        Calendar instance2 = Calendar.getInstance();
        instance2.setTimeInMillis( currentTimeMillis );
        int currTimeYear = instance2.get( Calendar.YEAR );
        int currTimeMonth = instance2.get( Calendar.MONTH );
        int currTimeDay = instance2.get( Calendar.DAY_OF_MONTH );

        if( preOpenYear == currTimeYear && preOpenMonth == currTimeMonth && currTimeDay == preOpenDay ){
            return false;
        }
        preferenceUtils.saveOpenAppDateTime( ""+currentTimeMillis );
        return true;
    }

    /**
     * 显示开屏广告弹窗
     */
//    public void showAdvertDialog(  AdvertisingBean.DataBean dataBean){
//        advertDialog = new AdvertDialog();
//        advertDialog.setCancelable( false );
//        advertDialog.showDialog( getSupportFragmentManager(), dataBean.getPhoto()  ,  new AdvertDialog.OnDialogListener() {
//
//            @Override
//            public void toDetail() {
//                //跳转到广告详情
//                Bundle bundle = new Bundle();
//                //1-有赞课程 2-文章 等于1时 会有链接 等于2时，跳转文章详情
//                if( dataBean.getAdType() == 1 ){
//                    //有赞课程
//                    bundle.putInt( ValueConstants.Actions.WEB_PAGE_TYPE , ValueConstants.WebConstants.OUTSIDE_LINK );
//                    bundle.putString( ValueConstants.Actions.WEB_PAGE_LINK , dataBean.getUrl() );
//                }else{
//                    //文章
//                    bundle.putString( "objectId" , TextUtils.isEmpty( ""+dataBean.getArticleId() ) ? "" : ""+dataBean.getArticleId() );
//                    bundle.putInt( ValueConstants.Actions.WEB_PAGE_TYPE , ValueConstants.WebConstants.ARTICLE_DETAIL );
//                }
//                showActivity( CommonWebActivity.class , bundle );
//                if( advertDialog != null ){
//                    advertDialog.dismiss();
//                }
//            }
//
//            @Override
//            public void close() {
//                if( advertDialog != null ){
//                    advertDialog.dismiss();
//                }
//            }
//        });
//    }

    @Override
    public void initData() {
//        new Handler().postDelayed(new Runnable() {
//            @Override
//            public void run() {
//                boolean notifyEnabled = NotificationUtil.isNotifyEnabled(MainActivity.this);
//                if (!notifyEnabled){
//                    boolean lastMessageTime = preferenceUtils.getLastMessageTime();
//                    if (!lastMessageTime) {
//                            PopWindowUtil.initopenMesageWindow(MainActivity.this, bottomMenuLayout);
//                    }
//                }
//            }
//        },1000);
        addParentLogin();
    }



    /**
     * 环信IM登录
     * @param userName
     * @param password
     */
    private void huanXixIMLogin( String userName , String password ){
//        EMClient.getInstance().login(userName,password,new EMCallBack() {//回调
//            @Override
//            public void onSuccess() {
//                EMClient.getInstance().groupManager().loadAllGroups();
//                EMClient.getInstance().chatManager().loadAllConversations();
//                Log.i("TAG", "登录聊天服务器成功！");
//            }
//
//            @Override
//            public void onProgress(int progress, String status) {
//                Log.d("main", "登录聊天服务器进度！");
//            }
//
//            @Override
//            public void onError(int code, String message) {
//                Log.d("main", "登录聊天服务器失败！");
//            }
//        });
    }

    /**
     * 获取底部菜单栏的高度
     * @return
     */
    public int getBottomMenuHeight(){
        return bottomView == null ? 0 : bottomView.getHeight();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        EventBus.getDefault().unregister( this );
    }

    @Subscribe( threadMode = ThreadMode.MAIN )
    public void handleBusEvent( BaseEvent event ){
        if( event != null && event.getCode() == BaseEvent.EventCodeContains.FINISH_MAIN_ACTIVITY
                && !TextUtils.isEmpty( event.getName() )
                && event.getName().equals( BaseEvent.EventNameContains.FINISH_MAIN_ACTIVITY ) ){
            finish();
        }else if( event != null && event.getCode() == BaseEvent.EventCodeContains.TO_LIVE_LIST_PAGE
                && !TextUtils.isEmpty( event.getName() )
                && event.getName().equals( BaseEvent.EventNameContains.TO_LIVE_LIST_PAGE ) ){
            //到直播列表
            onClickChange( 2 );
        }else if( event != null && event.getCode() == BaseEvent.EventCodeContains.TO_PATRIARCH_COURSE_FRAGMENT
                && !TextUtils.isEmpty( event.getName() )
                && event.getName().equals( BaseEvent.EventNameContains.TO_PATRIARCH_COURSE_FRAGMENT ) ){
            //到家长课堂
            onClickChange( 1 );
        }else if( event != null && event.getCode() == BaseEvent.EventCodeContains.TO_CLASSCRICLE_FRAGMENT
                && !TextUtils.isEmpty( event.getName() )
                && event.getName().equals( BaseEvent.EventNameContains.TO_CLASSCRICLE_FRAGMENT ) ){
            //到班级圈
          new Handler().postDelayed(new Runnable() {
              @Override
              public void run() {
                  onClickChange( 0 );
              }
          },800);

        }
    }

    @Override
    protected void onNewIntent(Intent intent) {
        if( intent == null ){
            return;
        }
        Bundle extras = intent.getExtras();
        if( extras == null ){
            return;
        }
//        String fromClass = extras.getString("fromClass");//重新返回首页处理
//        if( !TextUtils.isEmpty( fromClass ) && MyMessageActivity.class.getSimpleName().equals( fromClass )
//                || PayResultActivity.class.getSimpleName().equals( fromClass )){
//            int tabPosition = extras.getInt("tabPosition");
//            isHandPosition = extras.getBoolean("isHandPosition");
//            this.tabPosition = tabPosition;
//        }

            // 是否退出App的标识
            boolean isExitApp = intent.getBooleanExtra("exit", false);
            if (isExitApp) {
                // 关闭自身
                this.finish();
            }

    }

    @Override
    public boolean onKeyDown( int keyCode, KeyEvent event ) {
        Log.i( "TAG" , "=================onKeyDown=================" + keyCode );
        if (keyCode == KeyEvent.KEYCODE_BACK) {
            if (System.currentTimeMillis() - lastTime > 2000) {
                lastTime = System.currentTimeMillis();
                ToastUtils.shortToast("再按一次退出");
                return false;
            }
            finish();
            System.exit(0);
            //关闭所有粘性总线
        }
        return super.onKeyDown( keyCode, event);
    }

    public void showOrHidePoint( int value ){
        if( value <= -1 ){
            messagePointFrameLayout.setVisibility( View.GONE );
            badgeView.hide();
            pointNumLayout.setVisibility( View.GONE );
        }else if( value == 0 ){
            messagePointFrameLayout.setVisibility( View.VISIBLE );
            messagePointFrameLayout.setBackground( null );
            badgeView.show();
            pointNumLayout.setVisibility( View.GONE );
        }else if( value > 0 ){
            messagePointFrameLayout.setVisibility( View.VISIBLE );
            messagePointFrameLayout.setBackgroundResource( R.drawable.bg_ffffff_point_circle_corner_solid_drawable );
            pointNumLayout.setVisibility( View.VISIBLE );
            messagePointText.setText( "7" );
            badgeView.hide();
        }
    }

    @Override
    public void onGranted(@NonNull List<String> permissions) {
        if( !isExecGrant ){//版本更新
            versionUpdateModule.checkVersion( false );
        }
        isExecGrant = true;
    }

    @Override
    public void onDenied(@NonNull List<String> permissions) {

    }

    @Override
    public void onComeback() {

    }

    @Override
    public void onIntercept(boolean isIntercept) {
        this.isIntercept = isIntercept;
        if( !isIntercept ){
            showAdvert();
        }
    }

    @Override
    public void downloadResult(boolean isSuccess) {
        if( !isSuccess ){
            versionUpdateModule.showVersionUpdateDialog( versionUpdateModule.getNewVersion() , versionUpdateModule.getVersionInfo() , versionUpdateModule.isForce() );
        }
    }

    @Override
    public void onBack() {
        if( versionUpdateModule != null && versionUpdateModule.isKillApp() ){
            finish();
            System.exit(0);
        }
    }

    private void showAdvert(){
//        if( isShowAdvert() && !TextUtils.isEmpty( currentShowFragmentClassName )//判断是否显示开屏广告
//                &&  ClassGroupFragment.class.getSimpleName().equals( currentShowFragmentClassName ) ){
//            getOpenAppAdver();
//        }
    }


    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
//        UMShareAPI.get(this).onActivityResult(requestCode, resultCode, data);//友盟分享注册
    }


    //每日活跃
    private void addParentLogin() {
        try {
            userInfo = preferenceUtils.getUserInfo();
            Map<String , Object> params = new HashMap<>();
            //机构id
            params.put( "mechanicsmid" ,userInfo.getMechanismId() );
            //班级id
            params.put("groupid", userInfo.getClassIds());
            //页码
            params.put( "platformtype" ,"android" );

            huRequest.addParentLogin( params, new BaseObserver<String>() {
                @Override
                public void onNext(String json) {
    //                try {
    //                    if( TextUtils.isEmpty( json )){
    //                        ToastUtils.longToast( getResources().getString( R.string.get_data_fail ));
    //                        return;
    //                    }
    //                    MyVideoCollectListBean bean = JSON.parseObject( json , MyVideoCollectListBean.class );
    //                    if( bean == null ){
    //                        ToastUtils.longToast( getResources().getString( R.string.get_data_fail ));
    //                        return;
    //                    }
    //                    if( bean.getCode() == HttpConstants.RESPONSE_CODE_200 ){
    //
    //
    //                    }else{
    //                        ToastUtils.longToast( bean.getMessage() );
    //                    }
    //                }catch (Exception e){
    //                    FeiLogUtil.i("fei",e.toString());
    //                }
                }
            });
        }catch (Exception e){
            FeiLogUtil.i("fei",e.toString());
        }
    }


//    /**
//     * 更新的Handler
//     */
//    private Handler mUIHandler = new Handler() {
//
//        @Override
//        public void handleMessage(Message msg) {
//            switch (msg.what) {
//                case ON_EMOJI_CHANGE: { // 监听表情界面的变化
//                    emojiWidget.refreshWidgetUI(msg);
//                    break;
//                }
//            }
//        }
//    };



        private void ceShiJson() {
            Map<String, Object> params = new HashMap<>();

            JSONObject json = new JSONObject();
            json.put("dir","desc");
            json.put("limit",10);
            json.put("simple",1);
            json.put("sqlSort","id");
            json.put("start",1);
            JSONObject jsonSecond = new JSONObject();
            jsonSecond.put("mechanismId",userInfo.getMechanismId());
            jsonSecond.put("onFirstPage",1);
            json.put("data",jsonSecond);
//        params.put("path", MyJsonUrl.GET_NO_SEE_SCHOOL_TEACHER);
//        params.put("param", json.toString());


            RequestBody body = RequestBody.create(okhttp3.MediaType.parse("application/json; charset=utf-8"), json.toString());
            huRequest.ceShiJson( body, new BaseObserver<String>() {
                @Override
                public void onNext(String json) {
                    try {
                        if (TextUtils.isEmpty(json)) {
                            ToastUtils.longToast(getResources().getString(R.string.get_data_fail));
                            return;
                        }
//                        GetNoSeeTeacherBean bean = JSON.parseObject(json, GetNoSeeTeacherBean.class);
//                        if (bean == null) {
//                            ToastUtils.longToast(getResources().getString(R.string.get_data_fail));
//                            return;
//                        }
//                        if (bean.getCode() == HttpConstants.RESPONSE_CODE_200) {
//                            if (teacherlist != null && teacherlist.size() > 0 && page == 1) {
//                                teacherlist.clear();
//                            }
//                            List<GetNoSeeTeacherBean.DataBean.ListBean> list = bean.getData().getList();
//                            if (list != null) {
//                                teacherlist.addAll(list);
//                                canSeeAdapter.notifyDataSetChanged();
//                            }
//
//                        } else{
//                            ToastUtils.longToast( bean.getMessage() );
//                        }
                    } catch (Exception e) {
                        FeiLogUtil.i("fei", e.toString());
                    }

                }
            });
        }



    private void ceShiMap() {
        Map<String, Object> params = new HashMap<>();
        //机构id
        params.put("userid", userInfo.getId());
//        //页码
        params.put("usertype", 1);//1：机构， 2：家长 3：老师 返回0为默认图片
//        params.put( "start" ,1 );

        huRequest.getFengMianImage(params, new BaseObserver<String>() {
            @Override
            public void onNext(String json) {
                try {
//                    if (TextUtils.isEmpty(json)) {
//                        ToastUtils.longToast(getResources().getString(R.string.get_data_fail));
//                        return;
//                    }
//                    GetFengMianImageBean bean = JSON.parseObject(json, GetFengMianImageBean.class);
//                    if (bean == null) {
//                        ToastUtils.longToast(getResources().getString(R.string.get_data_fail));
//                        return;
//                    }
//                    if (bean.getCode() == HttpConstants.RESPONSE_CODE_200) {
//                        Glide.with(SchoolNewsActivity.this).load(bean.getData().getCover()).into(ivSchoolIcon);
//                    } else {
//                        ToastUtils.longToast(bean.getMessage());
//                    }
                } catch (Exception e) {
                    FeiLogUtil.i("fei", e.toString());
                }
            }
        });
    }


}
